package com.zenob.common.log;


public class Log {
	

	public final static int LEVEL_FATAL = 16;
	public final static int LEVEL_ERROR =  8;
	public final static int LEVEL_WARN	=  4;
	public final static int LEVEL_INFO  =  2;
	public final static int LEVEL_DEBUG =  1;
	public final static int LEVEL_TRACE =  0;

	public final static int LOG_LEVEL = LEVEL_TRACE; // static log level can be used
													 // to disable logger at compilation level
													 // without preprocessor
													 // usage : if(LOG_LEVEL>LEVEL_DEBUG) Log.d(TAG, "debug log")
	
	private static LogOutput mInstance = null;
	
	private Log() {
	}
	
	private final static LogOutput instance() {
		if(mInstance == null) {
			mInstance = new DummyLogOutput();
		}
		return mInstance;
	}
	
	public final static void initialize(LogOutput logOutput) {
		if(logOutput != null) mInstance = logOutput;
	}

	public final static void d(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_DEBUG) instance().log(LEVEL_DEBUG, TAG, message);
	}
	
	public final static void d(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_DEBUG) instance().log(LEVEL_DEBUG, TAG, message);
	}
	
	
	public final static void w(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_WARN) instance().log(LEVEL_WARN, TAG, message);
	}
	
	public final static void w(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_WARN) instance().log(LEVEL_DEBUG, TAG, message, t);
	}
	
	
	public final static void i(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_INFO) instance().log(LEVEL_INFO, TAG, message);
	}
	
	public final static void i(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_INFO) instance().log(LEVEL_INFO, TAG, message, t);
	}
	
	
	public final static void e(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_ERROR) instance().log(LEVEL_ERROR, TAG, message);
	}
	
	
	public final static void e(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_ERROR) instance().log(LEVEL_ERROR, TAG, message, t);
	}
	
	
	public final static void f(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_FATAL) instance().log(LEVEL_FATAL, TAG, message);
	}
	
	public final static void f(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_FATAL) instance().log(LEVEL_ERROR, TAG, message, t);
	}
	
	
	public final static void t(String TAG, Object message) {
		if(LOG_LEVEL<=LEVEL_TRACE) instance().log(LEVEL_TRACE, TAG, message);
	}
	
	public final static void t(String TAG, Object message, Throwable t) {
		if(LOG_LEVEL<=LEVEL_TRACE) instance().log(LEVEL_TRACE, TAG, message, t);
	}

}
